#!/usr/bin/env python 
# -*- coding:utf-8 -*-
"""
@Time:2021/11/19 7:47 下午"
@Author:lydia_liu"
@File:bicycle.py
@function:
"""
"""
bicycle(自行车类)
    属性：model(型号)，color（颜色）
    方法：run(km)方法，打印骑行公里数，骑行距离可以通过参数传入
ebicycle(电自行车类)
    属性：volume(电量)
    look_style()查看车辆信息
    fill_charge(vol)充电方法
    run(km)方法，用于骑行，每骑行10km消耗1度电，当电量消耗完时调用bicycle的run方法骑行
"""
class Bicycle:

    def __init__(self,model,color):
        #自行车型号和颜色
        self.model = model
        self.color = color

    def run(self,km):
        print(f"骑行了{km}公里")


class EBicycle(Bicycle):

    def __init__(self,volume,model,color):
        self.volume = volume
        super().__init__(model,color)

    def look_style(self):
        print(f"查看车的型号：{self.model},车的颜色为：{self.color}")

    def fill_charge(self,vol):
        #当前电量 = 本身的电量 + 充电的电量
        self.volume = self.volume + vol

        if self.volume < 30:
            print(f"充电{vol}度电！,现在充电后的电量为：{self.volume}")
        else:
            raise Exception("充电太多了，装不下了！")

    #电动的骑行方法
    def run(self,km):
        #获取目前电量可以走的公里数
        power_km = self.volume * 10
        rest_vol = 0
        if power_km > km:
            print(f"用电骑{km}km")
            rest_vol = self.volume - km /10
        else:
            print(f"电骑行了{power_km}km")
            print("没电了")
            super(EBicycle, self).run(km-power_km)
        return rest_vol




if __name__ == "__main__":
    # bike = Bicycle("b737","red")
    # bike.run(10)

    ebike = EBicycle(10,26,"红色")
    ebike.look_style()
    ebike.fill_charge(5)
    rest_vol = ebike.run(120)
    print(f"剩余电量{rest_vol}度")


